package com.zmn.mcc.permit.client.boot.autoconfigure;

import com.zmn.base.common.data.dubbo.interfaces.company.CompanyListRemoteService;
import com.zmn.mcc.dubbo.dto.DubboConsts;
import com.zmn.mcc.dubbo.interfaces.staff.StaffPermitRemoteService;
import com.zmn.mcc.permit.client.aop.AliDubboPermitDataAspect;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * alibaba dubbo 数据权限的 自动装配类
 * @author LuJia
 * @version v1.0
 * @since 2020/06/22 18:11
 **/
@Configuration
@ConditionalOnProperty(
        name = {"dpermit.alidubbo.enabled"},
        havingValue = "true",
        matchIfMissing = false
)
@Slf4j
public class AliDubboPermitDataAutoConfiguration {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    StaffPermitRemoteService staffPermitRemoteService;

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    CompanyListRemoteService companyListRemoteService;

    @Bean
    public AliDubboPermitDataAspect controllerPermitDataAspect(){
        log.info("实例化 AliDubboPermitDataAspect success --------------------------------------------");
        return new AliDubboPermitDataAspect(staffPermitRemoteService, companyListRemoteService);
    }
}
